//
// Created by leisurexi on 12/6/20.
// oob_send.c
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#define BUF_SIZE 30

void error_handling(char *message) {
    fputs(message, stderr);
    fputc('\n', stderr);
    exit(1);
}

int main(int argc, char *argv[]) {
    int sock;
    struct sockaddr_in revc_addr;
    if (argc != 3) {
        printf("Usage : %s <IP> <port>\n", argv[0]);
        exit(1);
    }

    sock = socket(AF_INET, SOCK_STREAM, 0);
    memset(&revc_addr, 0, sizeof(revc_addr));
    revc_addr.sin_family = AF_INET;
    revc_addr.sin_addr.s_addr = inet_addr(argv[1]);
    revc_addr.sin_port = htons(atoi(argv[2]));

    if (connect(sock, (struct sockaddr *) &revc_addr, sizeof(revc_addr)) == -1)
        error_handling("connect() error");

    write(sock, "123", 3);
    send(sock, "4", 1, MSG_OOB);
    write(sock, "567", 3);
    send(sock, "890", 3, MSG_OOB);
    close(sock);
    return 0;
}